package com.jy.rhin.infra.repo.document.submission.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.jy.rhin.infra.repo.document.submission.po.DocumentEntryPO;
import com.jy.rhin.sdk.dto.document.statistic.FindOrgListRespDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @author dhl
 * @date 2022/6/1
 * @Description
 */
@Mapper
@Repository
public interface DocumentEntryStaticsMapper extends BaseMapper<DocumentEntryPO> {

    /**
     * 根据医疗机构查询总数以及日增数
     *
     * @param objectPage
     * @param wrapper
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("SELECT org_name                                                                         AS orgName,   \n" +
            "       COUNT(1)                                                                         AS wendangZS, \n" +
            "       COUNT(if(creation_time >= #{startTime} AND creation_time < #{endTime}, 1, null)) AS rixinZS    \n" +
            "FROM t_document_entry                                                                                 \n" +
            "${ew.customSqlSegment}                                                                                  ")
    com.baomidou.mybatisplus.extension.plugins.pagination.Page<FindOrgListRespDto> queryOrgListGroupOrgName(IPage<Object> objectPage
            , @Param(Constants.WRAPPER) QueryWrapper<Object> wrapper
            , @Param("startTime") Date startTime
            , @Param("endTime") Date endTime);

}
